﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace Isuka.Spiritual
{
    partial class Rules<T, A>
    {
        /// <summary>
        /// スキップしない
        /// </summary>
        public static readonly SkipFunc NoSkip = (i, c) => i;

        /// <summary>
        /// 条件に一致する項目をスキップ
        /// </summary>
        /// <param name="pred"></param>
        /// <returns></returns>
        public static SkipFunc SkipIf(Func<T, bool> pred)
        {
            Contract.Requires<ArgumentNullException>(pred != null, "pred");
            Contract.Ensures(Contract.Result<SkipFunc>() != null);

            return (i, c) =>
            {
                while (!i.Equals(c.Last) && pred(i.Current))
                {
                    i.MoveNext();
                }
                return i;
            };
        }
    }
}
